<?php
// +----------------------------------------------------------------------
// | Created by PHPstorm: [ JRK丶Admin ]
// +----------------------------------------------------------------------
// | Copyright (c) 2019~2022 [LuckyHHY] All rights reserved.
// +----------------------------------------------------------------------
// | SiteUrl: http://www.luckyhhy.cn
// +----------------------------------------------------------------------
// | Author: LuckyHhy <jackhhy520@qq.com>
// +----------------------------------------------------------------------
// | Date: 2020/6/26 0026
// +----------------------------------------------------------------------
// | Description:
// +----------------------------------------------------------------------

namespace app\admin\controller;


use app\admin\model\AttachMent;
use app\common\controller\AdminBaseController;
use Jrk\Zipdown;
use think\facade\Db;

class AttachMents extends AdminBaseController
{
    protected function initialize()
    {
        parent::initialize(); // TODO: Change the autogenerated stub

        $this->model=new AttachMent();

        //附件类型
        $type=$this->model->field("type")->group("type")->select()->toArray();
        $this->assign("type",$type);
    }


    /**
     * @author: Hhy <jackhhy520@qq.com>
     * @date: 2020/7/2 0002
     * @describe:上传附件
     */
    public function uploadAttachment(){
       return $this->fetch("upattachment");
    }


    /**
     * @return string
     * @throws \Exception
     * @author: LuckyHhy <jackhhy520@qq.com>
     * @date: 2020/7/2 0002
     * @describe:获取图片附件
     */
    public function getImages(){
        $res=$this->model->GetImagesFiles();
        $this->assign('data', $res->toArray());
        $this->assign('page', $res->render());
        return $this->fetch();
    }



    /**
     * @author: Hhy <jackhhy520@qq.com>
     * @date: 2020/7/2 0002
     * @describe:打包下载
     */
    public function download(){
      $id= $this->request->param("id");
        if (is_array($id)){
            $ids=$id;
        }else{
            $ids=@explode(",",$id);
        }
        $data=$this->model->where('id', 'in',$ids)->select()->toArray();

        if (empty($data)) {
            $this->error("暂无数据");
        }

        $zip=new Zipdown();

        //打包下载  
        return $zip->zip_file($data);
    }



}